﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using VersionComparer.Base;
using VersionComparer.Comparer;
using VersionComparer.DataModel.Assemblies.Images;

namespace VersionComparer.DataModel.Assemblies
{
    [Serializable]
    public class CodeItem: AssemblyItemBase<MethodBody>
    {

        protected override void Initialize(MethodBody body)
        {
            IsPublic = true;
            base.Initialize(body);
            Text = string.Format ( "//Code hash: {0}", body == null? "":ASCIIEncoding.ASCII.GetString(body.GetILAsByteArray()).GetHashCode().ToString());
        }

        protected override string GetFullText(MethodBody value)
        {
            return Text;
        }
        protected override void BuildRtf(Base.RtfBuilder builder, bool differencesOnly, bool useParentColor)
        {
            //builder.Append("throw new ", keywordColor);
            //builder.Append("NotImplementedException", nameColor);
            //builder.AppendLine("();");
            builder.Append(Text, commentColor);
        }

        public override double Matches(ComparisonAlgorithm algorithm, ComparableItem other)
        {
            return Match.CertainMatch;
        }

        public override Difference DifferenceRelativeTo(ComparableItem otherItem)
        {
            if (otherItem.Text == Text)
                return Difference.None;
            else
            {
                return Difference.Value;
            }
        }

        protected override Image GetSpecificImage()
        {
            return AssemblyResources.Code;
        }
    }
}
